package com.netease.service;

import com.netease.common.NetServiceCommon;
import com.netease.domain.RepositoryDetail;
import com.netease.domain.RepositoryItem;
import com.sun.tools.javac.util.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

/**
 * Created by dongle on 2017/2/23.
 */
@Service
public class RepositoryService {
    private static String listUrl = "https://open.c.163.com/api/v1/repositories?offset=%d&limit=%d";
    private static String detailUrl = "https://open.c.163.com/api/v1/repositories/%d";
    @Autowired
    private NetServiceCommon netServiceCommon;

    public List<RepositoryItem> getList() throws IOException {
        List<RepositoryItem> listAll = netServiceCommon.getListAll(listUrl, RepositoryItem.class, "repositories", "offset", "limit");
        return listAll;
    }

    public RepositoryDetail getDetail(Long repostoryId) throws IOException {
        RepositoryDetail response = netServiceCommon.getResponse(String.format(detailUrl, repostoryId), RepositoryDetail.class);
        return response;
    }
}
